package com.ggh.jinjilive.ui.social.record;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.FragmentRecordBinding;
import com.ggh.jinjilive.ui.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class RecordFragment extends BaseFragment<FragmentRecordBinding> {
    private String[] mFragmentTitles = {"查看我的", "我查看的"};
    private int[] mFragmentStatus = {1, 2};

    private List<ExamineFragment> examineFragmentList = new ArrayList<>();
    private ProfitOrderAdapter profitOrderAdapter;
    @Override
    public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        return R.layout.fragment_record;
    }

    @Override
    public void initView() {
        super.initView();
        examineFragmentList.clear();
        for (int i = 0; i < mFragmentTitles.length; i++) {
            ExamineFragment examineFragment = new ExamineFragment(mFragmentStatus[i]);
            examineFragmentList.add(examineFragment);
        }
        profitOrderAdapter = new ProfitOrderAdapter(getChildFragmentManager());
        binding.vp.setAdapter(profitOrderAdapter);
        binding.vp.setOffscreenPageLimit(mFragmentTitles.length);
        binding.stlOrder.setViewPager(binding.vp, mFragmentTitles);
        binding.vp.setCurrentItem(0);
    }

    @Override
    public void initData() {
        super.initData();

    }


    class ProfitOrderAdapter extends FragmentPagerAdapter {
        public ExamineFragment examineFragment;

        public ProfitOrderAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public ExamineFragment getItem(int position) {
            return examineFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return examineFragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitles[position];
        }

        @Override
        public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            super.setPrimaryItem(container, position, object);
        }
    }
}
